<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  <body>
  
  </body>
  
  <script>
    setTimeout(() => {
      console.log('setTimeout start');
      
      Promise.resolve()
        .then(() => console.log('promise resolve1'))
        .then(() => console.log('promise resolve2'))
        .then(() => console.log('promise resolve3'))
        .then(() => console.log('promise resolve4'));
      
      new Promise((resolve) => {
        console.log('promise1 start');
        resolve();
      }).then(() => {
        console.log('promise1 end');
      });
      
      setTimeout(() => {
        console.log('inner setTimeout');
      });
      
      console.log('setTimeout end');
    }, 0);
    
    function promise2() {
      return new Promise((resolve) => {
        console.log('promise2');
        resolve();
      });
    }
    
    async function async1() {
      console.log('async1 start');
      await promise2();
      console.log('async1 end');
    }
    
    async1();
    
    console.log('script end');
    
    // 执行结果
    // async1 start
    // promise2
    // script end
    // async1 end
    // setTimeout start
    // promise1 start
    // setTimeout end
    // promise resolve1
    // promise1 end
    // promise resolve2
    // promise resolve3
    // promise resolve4
    // inner setTimeout
  </script>
</html>